import {login} from '@/api/login'
const user={
    state:{
        userName:'',
        token:''
    },
    mutations:{
        SET_TOKEN: (state, token) => {
            state.token = token
          },
          SET_NAME: (state, name) => {
            state.username = name
          }
    },
    actions:{
        //登录
       Login({commit},param){
            return new Promise((resolve, reject) => {
                 login(param).then(response=>{
                    var userInfo = response.data;
                    if(userInfo.code==200){
                        commit('SET_TOKEN', userInfo.token);
                        commit('SET_NAME', userInfo.username);
                        resolve();
                    }else{
                        reject();
                    }
                 }) 
                 .catch(error => {
                    reject(error)
                  })

            })
           
        }
    }
}
export default user